package com.empire.module.sporttery.controller.admin.football500firstbuy;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.sporttery.controller.admin.football500firstbuy.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500firstbuy.Football500FirstBuyDO;
import com.empire.module.sporttery.service.football500firstbuy.Football500FirstBuyService;

@Tag(name = "管理后台 - 500wan 必发大额交易明细")
@RestController
@RequestMapping("/sporttery/football500-first-buy")
@Validated
public class Football500FirstBuyController {

    @Resource
    private Football500FirstBuyService football500FirstBuyService;

    @PostMapping("/create")
    @Operation(summary = "创建500wan 必发大额交易明细")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-first-buy:create')")
    public CommonResult<Integer> createFootball500FirstBuy(@Valid @RequestBody Football500FirstBuySaveReqVO createReqVO) {
        return success(football500FirstBuyService.createFootball500FirstBuy(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新500wan 必发大额交易明细")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-first-buy:update')")
    public CommonResult<Boolean> updateFootball500FirstBuy(@Valid @RequestBody Football500FirstBuySaveReqVO updateReqVO) {
        football500FirstBuyService.updateFootball500FirstBuy(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除500wan 必发大额交易明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('sporttery:football500-first-buy:delete')")
    public CommonResult<Boolean> deleteFootball500FirstBuy(@RequestParam("id") Integer id) {
        football500FirstBuyService.deleteFootball500FirstBuy(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得500wan 必发大额交易明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-first-buy:query')")
    public CommonResult<Football500FirstBuyRespVO> getFootball500FirstBuy(@RequestParam("id") Integer id) {
        Football500FirstBuyDO football500FirstBuy = football500FirstBuyService.getFootball500FirstBuy(id);
        return success(BeanUtils.toBean(football500FirstBuy, Football500FirstBuyRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得500wan 必发大额交易明细分页")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-first-buy:query')")
    public CommonResult<PageResult<Football500FirstBuyRespVO>> getFootball500FirstBuyPage(@Valid Football500FirstBuyPageReqVO pageReqVO) {
        PageResult<Football500FirstBuyDO> pageResult = football500FirstBuyService.getFootball500FirstBuyPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Football500FirstBuyRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出500wan 必发大额交易明细 Excel")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-first-buy:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFootball500FirstBuyExcel(@Valid Football500FirstBuyPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Football500FirstBuyDO> list = football500FirstBuyService.getFootball500FirstBuyPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "500wan 必发大额交易明细.xls", "数据", Football500FirstBuyRespVO.class,
                        BeanUtils.toBean(list, Football500FirstBuyRespVO.class));
    }

}